<template>
	<navbar title="视频播放" :isBack="true"></navbar>
	<picture v-if="!Info.is_show" title="开发中~" imgPath="/static/image/quesheng.png"
		imgHeight="192rpx" imgWidth="335rpx" bg="#F4F4F8" :height="tools.clientTopHight(250)"></picture>
	<view class="page" v-else>
		<view class="" style="height: 376rpx;width: 100%;">
			<!-- <video-player :src="Info.video" :poster="Info.banner" controls :loop="true" :volume="0.6">
			</video-player> -->
			<video play-btn-position="center" :src="Info.video" autoplay  :poster="Info.banner" object-fit="fill" @fullscreenchange="screenChange" style="height: 376rpx;width: 100%;">
				<view src="" style="position: absolute;bottom: 10rpx;color: white;"
					:style="{'left':isWatermark?'30rpx':'100rpx','width': isWatermark?'158rpx':'138rpx','height':isWatermark? '31rpx':'28rpx'}">
					@闪击门球</view>
			</video>
 
		</view>
		<view class="header">
			<view class="title">
				<view class="title-left">
					{{Info.title}}
				</view>
			<view class="">
				<button class="title-right" style="background-color: white;padding: 0;" open-type="share">
					<view class="image">
						<image src="/static/image/share.png" mode="" style="width: 36rpx;height: 36rpx;"></image>
					</view>
					<view class="text">
						分享
					</view>
				</button>
			</view>
			</view>
			<view class="" style="margin-top: 20rpx;">
				<span class=""
					style="font-size: 18rpx;color: #EF6800;padding: 4rpx 12rpx;border: 1rpx solid #EF6800;border-radius: 10rpx;">
					已有{{Info.views}}人观看
				</span>
			</view>
		</view>


		<view class="" style="margin-top: 20rpx;padding: 30rpx;background-color: white;">
			<view class="" style="font-size: 36rpx;margin-bottom: 30rpx;">
				目录
			</view>
			<view class=""
				style="padding-bottom: 15rpx;border-bottom: 1rpx solid #E7E9EB;display: flex;margin-bottom: 15rpx;"
				v-for="item in Info.course" @click="clickVideo(item)">
				<view class="" style="width: 303rpx;height: 170rpx;border-radius: 10rpx;position: relative;">
					<image :src="item.banner" style="width: 303rpx;height: 170rpx;border-radius: 10rpx;" mode="">
					</image>
					<view class="" v-if="item.mask" style="position: absolute;top: 0;height: 170rpx;width: 100%;background-color: rgba(0, 0, 0, 0.4);display: flex;justify-content: center;align-items: center;color: white;">
						播放中
					</view>
				</view>
				<view class=""
					style="margin-left: 24rpx;height: 170rpx;display: flex;flex-direction: column;justify-content: space-between;">
					<view class="" style="font-size: 25rpx;">
						{{item.title}}
					</view>
					<view class="">
						<span class="" v-if="item.is_lock == '0'"
							style="font-size: 18rpx;color: #FF8056;padding: 4rpx 12rpx;border: 1rpx solid #FF8056;border-radius: 10rpx;">
							免费播放
						</span>
						<span class="" v-if="item.is_lock == '1'"
							style="font-size: 18rpx;color: #3F4780;padding: 4rpx 12rpx;border: 1rpx solid #3F4780;border-radius: 10rpx;">
							报名赛事观看
						</span>
						<span class="" v-if="item.is_lock == '2'"
							style="font-size: 18rpx;color: #FF8056;padding: 4rpx 12rpx;border: 1rpx solid #FF8056;border-radius: 10rpx;">
							已有{{item.views}}人观看
						</span>
						<view class="" style="font-size: 24rpx;color: #999999;margin-top: 18rpx;">
							<span v-if="item.duration">视频时长：{{item.duration}}</span>
						</view>
					</view>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
 
	import tools from '@/utils/tools';
	import { ref, reactive } from 'vue'
	import { courseDetail, videoDetail,addViews } from '@/service/api/index'

	import { onLoad } from '@dcloudio/uni-app'
	const isWatermark = ref(true)
	const tabIndex = ref(0)
	const videoPlayerRef = ref(null)

	const Info = reactive({
		banner: "",
		id: 0,
		title: "",
		classify_id: 0,
		name: "",
		introduce: "",
		image: "",
		price: "",
		state: 0,
		goods: {},
		course: [] as any,
		enroll_id: "",
		is_enroll: "",
		views: "",
		video: "",
		is_show:0,
	})
	 
	const popShow = ref(false);
	const current = ref(0)
	const specs = ref('')
	const id = ref('')
	onLoad((options : any) => {

		id.value = options.id;
		 console.log(options);
		getData()
	})
	const screenChange = (e : any) => {
		let fullScreen = e.detail.fullScreen; // 值true为进入全屏，false为退出全屏
		console.log(fullScreen)
		if (fullScreen) {
			isWatermark.value = false
		} else {
			isWatermark.value = true
		}
	}
	//获取数据
	const getData = async () => {
		const res = await videoDetail({ id: id.value });
		console.log(res);

		for (let key in Info) {
			Info[key] = res.msg[key]
		}
		Info.course.forEach((item,index)=>{
			if(item.id == id.value){
				item['mask'] = true;
			}
		})

		console.log(Info.video);
	}
		
	const clickVideo = async(item:any)=>{
		 if (item.is_lock == '1') {
		 	tools.showToast('报名赛事观看')
		 	return
		 };
		 if(item.mask){
			 return
		 }
		 await addViews({id:item.id});
		tools.navTo('/pagesB/course/video?id=' + item.id,4);
	}
	const tabsChange = (index : number) => {
		console.log(index);
		tabIndex.value = index;
		if (index == 1) {
			//点击目录
			uni.createSelectorQuery().select('#mulu').boundingClientRect((rect : any) => {
				console.log(rect);
				if (rect) {
					uni.pageScrollTo({
						scrollTop: 604 - 110,
						duration: 500
					})

				}
			}).exec()
		}
	}
</script>

<style scoped lang="scss">
	.page {
		min-height: calc(100vh - 68px);
		background-color: #F8F8F9;
		padding-bottom: 168rpx;
	}

	.header {
		background-color: white;
		padding: 30rpx;

		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.title {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.title-left {
				font-size: 36rpx;
				font-weight: bold;
			}

			.title-right {
				display: flex;
align-items: center;
				.image {
					width: 36rpx;
					height: 36rpx;
				}

				.text {
					font-size: 28rpx;
					margin-left: 5rpx;
				}
			}
		}

		.subtitle {
			color: #787878;
			font-size: 28rpx;
		}

		.price {
			color: #F00505;
			font-size: 40rpx;

			span {
				font-size: 20rpx;
			}
		}

	}

	.active {
		background-color: #40518A;
		color: white;
	}

	.noactive {
		background-color: #F5F6F8;
		color: black;
	}

	.pay {
		background: linear-gradient(90deg, #5062A7 0%, #354678 100%);
	}

	.disabled {
		background-color: #ABABAB;
	}

	:deep(.u-tab-item) {
		color: black !important;
		font-size: 36rpx !important;
	}
</style>